// Dom7
var $$ = Dom7;
// Framework7 App main instance
var app = new Framework7({
	root: '#app', // App root element
	id: 'io.yachtar.app', // App bundle ID
  	name: 'Yachtar', // App name
	theme: 'auto', // Automatic theme detection
	dialog: {
		// set default title for all dialog shortcuts
		title: '提示',
		// change default "OK" button text
		buttonOk: '确认',
	  }
});

// Init/Create main view
var mainView = app.views.create('#view-home', {
	url: '/'
});

var cordova_app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },
    onDeviceReady: function() {
        this.receivedEvent('deviceready');
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
		QRScanner.destroy(function(status){
			console.log(status);
		});
    }
};
cordova_app.initialize();

$(document).ready(function(){
	var houseid = sessionStorage.getItem("houseid");
	var params = {houseid:houseid};
	call_remote(REQUEST_TYPE29,{houseid:houseid},function(data){
		document.getElementById("location").innerHTML = data[0].location;
		getpayinfo(data[0]);
	});
});

$$('#back').on('click', function () {
	window.location.href = "../../plugin/pay/choose.html";
});	
$$('#cancelpay').on('click', function () {
	window.location.href = "../../plugin/pay/choose.html";
});	
$$('#confirmpay').on('click', function () {
	sessionStorage.setItem("paytype",3);
	window.location.href = "../../plugin/homepage/scan.html";
});	

function getpayinfo(data){
	var now = new Date(); 
	var budgetData = {};
	var tempbudgetData = [];
	budgetData.pi_sBuildType = data.buildtype;
	budgetData.pi_sHouseType = data.housetype;
	budgetData.pi_sStructType = data.structtype;
	budgetData.pi_sHouseUseType = data.houseusetype;
	budgetData.pi_sIsHasElevator = data.ishaselevator;
	budgetData.pi_sOwnerType = data.ownertype;
	budgetData.pi_sBudgetDate = 1900 + now.getYear() + '-' + (now.getMonth() + 1)  + '-' + now.getDate();//data.buydate;
	budgetData.pi_cyArea = data.payarea;
	budgetData.pi_cyAmount = data.buyamount;
	budgetData.pi_cyPrice = data.cost;
	budgetData.villageid = data.villageid;
	budgetData.houseid = data.houseid;
	tempbudgetData.push(budgetData);
	call_remote(REQUEST_TYPE49,{datas:tempbudgetData},function(data){
		document.getElementById("amount").innerHTML = data[0].po_cyOwner;
		sessionStorage.setItem("payamount", data[0].po_cyOwner);
		sessionStorage.setItem("rate", data[0].po_cyPayRate_Owner);
		sessionStorage.setItem("calculatetype", data[0].po_sCalType_owner);
	});
}